#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 1000005;

int n, k, num[maxn];

struct _data {
	int w, pos;
} q[maxn];

inline int iread() {
	int f = 1, x = 0; char ch = getchar();
	for(; ch < '0' || ch > '9'; ch = getchar()) f = ch == '-' ? -1 : 1;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	return f * x;
}

int main() {
	n = iread();
	for(int i = 1; i <= n; i++) num[i] = iread();
	k = iread(); k = min(k, n);

	int h = 1, t = 0;
	for(int i = 1; i < k; i++) {
		for(; h <= t && q[t].w <= num[i]; t--);
		q[++t] = (_data) {num[i], i};
	}

	for(int i = k; i <= n; i++) {
		for(; h <= t && q[h].pos <= i - k; h++);
		for(; h <= t && q[t].w <= num[i]; t--);
		q[++t] = (_data) {num[i], i};
		printf("%d ", q[h].w);
	}

	return 0;
}